package com.wizz.trade.information.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wizz.trade.information.dto.page.CurrencyPageDto;
import com.wizz.trade.information.entity.Currency;
import com.wizz.trade.information.mapper.CurrencyMapper;
import com.wizz.trade.information.service.CurrencyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wizz.trade.common.PageVo;
import com.wizz.trade.util.PageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 币种表 服务实现类
 * </p>
 *
 * @author fyftless
 * @since 2023-04-02 04:26:06
 */
@Service
public class CurrencyServiceImpl extends ServiceImpl<CurrencyMapper, Currency> implements CurrencyService {

    @Resource
    private CurrencyMapper currencyMapper;

    @Override
    public void addCurrency(Currency currency) {
        currencyMapper.insert(currency);
    }

    @Override
    public void updateCurrency(Currency currency) {
        currencyMapper.updateById(currency);
    }

    @Override
    public void deleteCurrency(Integer id) {
        currencyMapper.deleteById(id);
    }

    @Override
    public PageVo<Currency> getPage(CurrencyPageDto currencyPageDto) {
        LambdaQueryWrapper<Currency> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(currencyPageDto.getName()),Currency::getName, currencyPageDto.getName());
        queryWrapper.eq(!Objects.isNull(currencyPageDto.getIsLocal()),Currency::getIsLocal,currencyPageDto.getIsLocal());
        IPage<Currency> page = currencyMapper.selectPage(PageUtil.initPage(currencyPageDto), queryWrapper);
        return new PageVo<>(page);
    }

    @Override
    public List<Currency> getAll() {
        return currencyMapper.selectList(null);
    }

    @Override
    public List<Map<Integer, String>> getNames() {
        return currencyMapper.getNames();
    }

    @Override
    public List<Map<Integer, String>> getOptions() {
        return currencyMapper.getOptions();
    }

}
